package com.wicket.okrapp.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrapp.biz.service.dto.req.*;
import com.wicket.okrapp.biz.service.dto.res.*;
import com.wicket.okrapp.common.util.RedisUtil;

import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.wicket.okrapp.biz.service.dto.common.ConfSchemeItemResultDto;
import cn.hutool.core.collection.CollectionUtil;
import com.wicket.okrapp.biz.service.nb.NbConfScheme;
import com.wicket.okrapp.base.service.MSpaceService;
import com.wicket.okrframework.integration.dto.QuerySpaceListComRespDto;
import com.wicket.okrframework.integration.dto.QuerySpaceListComReqDto;
import com.wicket.okrframework.integration.dto.FrameworkSpaceDto;
import com.wicket.okrapp.common.exception.Assert;
import com.wicket.okrframework.integration.FwBaseBaseClient;
import com.wicket.okrcomponent.integration.FwCompConfSchemeClient;
import com.wicket.okrcomponent.integration.FwCompInterfaceModeClient;
import com.wicket.okrcomponent.integration.dto.QueryInitSpaceConfDetailComRespDto;
import com.wicket.okrcomponent.integration.dto.QueryInitSpaceConfDetailComReqDto;
import com.wicket.okrapp.base.service.MOmsTaskService;
import com.wicket.okrframework.integration.FwBaseInterfaceModeClient;
import com.wicket.okrapp.biz.service.InterfaceModeService;
import com.wicket.okrcalc.integration.FwCalcInterfaceModeClient;
import com.wicket.okrfinance.integration.FwFinanceInterfaceModeClient;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class ConfSchemeServiceImpl
  implements com.wicket.okrapp.biz.service.ConfSchemeService {

  @Resource
  private RedisUtil redisUtil;
//@Resource
 //private MCustomFieldsService mCustomFieldsService;
@Resource
  private NbConfScheme nbConfScheme;
@Resource
  private MSpaceService mSpaceService;
//@Resource
 //private undefinedService undefinedService;
@Resource
  private FwBaseBaseClient fwBaseBaseClient;
@Resource
  private FwCompConfSchemeClient fwCompConfSchemeClient;
@Resource
  private FwCompInterfaceModeClient fwCompInterfaceModeClient;
@Resource
  private MOmsTaskService mOmsTaskService;
@Resource
  private FwBaseInterfaceModeClient fwBaseInterfaceModeClient;
@Resource
  private InterfaceModeService interfaceModeService;
@Resource
  private FwCalcInterfaceModeClient fwCalcInterfaceModeClient;
@Resource
  private FwFinanceInterfaceModeClient fwFinanceInterfaceModeClient;
/**
   * D3转换配置项匹配答案（特殊方法）[2576]
   * gen by moon at 7/5/2023, 1:49:30 AM
   */
  @Trace(operationName = "D3转换配置项匹配答案（特殊方法）")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public TransitionConfItemMatchAnswerRespDto transitionConfItemMatchAnswer(TransitionConfItemMatchAnswerReqDto reqDto){
    
      
      TransitionConfItemResultToAnswerRespDto rowToColumnRes_1 =null;
//步骤0: M3转换配置项结果转答案（特殊方法） - transitionConfItemResultToAnswer
     //ModelCode: rowToColumn
        TransitionConfItemResultToAnswerRespDto rowToColumnRes = null;
    TransitionConfItemResultToAnswerReqDto rowToColumnReq=new TransitionConfItemResultToAnswerReqDto();
  if(reqDto!= null&&  reqDto.getConfSchemeItemResultList() !=null&& !CollectionUtil.isEmpty(reqDto.getConfSchemeItemResultList())){
      rowToColumnReq.setConfSchemeItemResultList(reqDto.getConfSchemeItemResultList().stream().map(item -> BeanUtil.toBean(item, ConfSchemeItemResultDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:79730_1
    }
  
    /*M3转换配置项结果转答案（特殊方法）[2448]  导入变更字段使用，将excel每行数据转换成列 */
    
      rowToColumnRes = nbConfScheme.transitionConfItemResultToAnswer(rowToColumnReq);
      
      
      rowToColumnRes_1 = rowToColumnRes;
    
TransitionConfItemMatchAnswerRespDto retData = new TransitionConfItemMatchAnswerRespDto();
  if(rowToColumnRes_1!=null){
      retData.setConfSchemeId(rowToColumnRes_1.getConfSchemeId());//SimpleFieldAssign//sourceId:79781_1
retData.setFatherCycleType(rowToColumnRes_1.getFatherCycleType());//SimpleFieldAssign//sourceId:79782_1
retData.setFatherSubcycleQuantity(rowToColumnRes_1.getFatherSubcycleQuantity());//SimpleFieldAssign//sourceId:79784_1
retData.setMidCycleType(rowToColumnRes_1.getMidCycleType());//SimpleFieldAssign//sourceId:79785_1
retData.setMidSubcycleQuantity(rowToColumnRes_1.getMidSubcycleQuantity());//SimpleFieldAssign//sourceId:79786_1
retData.setSubcycleType(rowToColumnRes_1.getSubcycleType());//SimpleFieldAssign//sourceId:79787_1
retData.setCycleMode(rowToColumnRes_1.getCycleMode());//SimpleFieldAssign//sourceId:79789_1
retData.setHeadCopywriter(rowToColumnRes_1.getHeadCopywriter());//SimpleFieldAssign//sourceId:79793_1
retData.setEvaThemeSketch(rowToColumnRes_1.getEvaThemeSketch());//SimpleFieldAssign//sourceId:79794_1
retData.setButtonCopywriter(rowToColumnRes_1.getButtonCopywriter());//SimpleFieldAssign//sourceId:79795_1
retData.setResultCycleType(rowToColumnRes_1.getResultCycleType());//SimpleFieldAssign//sourceId:79796_1
retData.setUseObjectTypeCode(rowToColumnRes_1.getUseObjectTypeCode());//SimpleFieldAssign//sourceId:79818_1
retData.setIsOpenPlanSchemeClass(rowToColumnRes_1.getIsOpenPlanSchemeClass());//SimpleFieldAssign//sourceId:79932_1
retData.setCycleSystemCode(rowToColumnRes_1.getCycleSystemCode());//SimpleFieldAssign//sourceId:79820_1
retData.setIsOpenBudget(rowToColumnRes_1.getIsOpenBudget());//SimpleFieldAssign//sourceId:90642_1
retData.setAccountUnit(rowToColumnRes_1.getAccountUnit());//SimpleFieldAssign//sourceId:90643_1
retData.setBudgetHierarchy(rowToColumnRes_1.getBudgetHierarchy());//SimpleFieldAssign//sourceId:90644_1
    }
  

  
  
return retData;
  }
/**
   * D3执行初始化空间配置(公共)[9604]
   * gen by moon at 5/19/2024, 2:07:24 AM
   */
  @Trace(operationName = "D3执行初始化空间配置(公共)")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public ImplementInitSpaceConfComRespDto implementInitSpaceConfCom(ImplementInitSpaceConfComReqDto reqDto){


      //virtualUsage D1-2查询空间列表(管理)(公共)  68571
      QuerySpaceListComRespDto querySpaceListComRespDto = null;
    QuerySpaceListComReqDto querySpaceListComReqDto=new QuerySpaceListComReqDto();


    /*D1-2查询空间列表(管理)(公共)[3315]   */

      querySpaceListComRespDto = fwBaseBaseClient.querySpaceListCom(querySpaceListComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;



if((querySpaceListComRespDto!= null&&  querySpaceListComRespDto.getSpaceList() !=null && querySpaceListComRespDto.getSpaceList().size()>0)) {
        //if(D1-2查询空间列表(管理)(公共).空间列表数据集条数 大于 0)  68572

//ModelCode: circulationCollections
        for (FrameworkSpaceDto circulationCollectionsRes: querySpaceListComRespDto.getSpaceList()){

QueryInitSpaceConfDetailComRespDto queryInitSpaceConfDetailComRespDto = null;
    QueryInitSpaceConfDetailComReqDto queryInitSpaceConfDetailComReqDto=new QueryInitSpaceConfDetailComReqDto();
if(circulationCollectionsRes!=null){
      queryInitSpaceConfDetailComReqDto.setSpaceId(circulationCollectionsRes.getSpaceId());//SimpleFieldAssign//sourceId:1807881_1_68577
    }

    /*D2查询初始化空间配置(公共)[9610]   */
    Assert.isNull(queryInitSpaceConfDetailComReqDto.getSpaceId(),"D3执行初始化空间配置(公共)-D2查询初始化空间配置(公共)-空间ID不能为空",false);
      queryInitSpaceConfDetailComRespDto = fwCompConfSchemeClient.queryInitSpaceConfDetailCom(queryInitSpaceConfDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;



//ModelCode: circulationEnd
        }

      }
ImplementInitSpaceConfComRespDto retData = new ImplementInitSpaceConfComRespDto();





return retData;
  }


  //
}
